package im

import (
	"fmt"
	"github.com/zeromicro/go-zero/core/logx"
	"mall/service/forum/api/internal/logic/im"
	"net/http"
	"net/url"
	"strconv"

	"mall/common/resultx"
	"mall/service/forum/api/internal/handler/util"
	"mall/service/forum/api/internal/svc"
	"mall/service/forum/api/internal/types"
)

// 添加售后申请
func ImHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.ImReq
		u, err := url.Parse(r.RequestURI)
		if err != nil {
			logx.Infof("Error parsing URL:%+v", err)
			return
		}
		params, err := url.ParseQuery(u.RawQuery)
		if err != nil {
			logx.Infof("Error parsing query:%+v", err)
			return
		}
		fmt.Println(params, "par:")
		req.UserId, err = strconv.ParseUint(params.Get("userId"), 10, 64)
		fmt.Println(req, "req:")
		l := im.NewImLogic(r.Context(), svcCtx)
		var headers []*types.Header
		resp, err := l.Im(&req, w, r)
		w = util.SetHeaders(w, headers)
		resultx.HttpResult(r, w, resp, err)
	}
}
